function PasOtmlProject(xmlDoc) {
	this.xmlDoc = xmlDoc;
	this.rootNode = null;
	
	this.generateNode();
}

PasOtmlProject.prototype.generateNode = function() {
	this.rootNode = new Node();
	this.rootNode.type = "Project";
	this.rootNode.id = 0;
	
	var activities = this.xmlDoc.getElementsByTagName("OTPasActivity");
	for (var i=0; i < activities.length; i++) {
		var activity = activities[i];
		var activityNode = new Node();
		activityNode.parent = this.rootNode;
		activityNode.id = activityNode.parent.id + ":" + i;
		activityNode.setType("Activity");
		var steps = activity.getElementsByTagName("stepList")[0].getElementsByTagName("step");
		for (var j=0; j < steps.length; j++) {
			var stepNode = new Node();
			stepNode.parent = activityNode;
			stepNode.id = stepNode.parent.id + ":" + j;
			stepNode.setType("Step");
			stepNode.setContent(steps[j]);
			activityNode.addChildNode(stepNode);
		}
		this.rootNode.addChildNode(activityNode);
	}
}

Node.prototype.getContentHtml = function() {
	var content = "";
	if (this.content != null && 
			(this.content.getElementsByTagName("OTReadingPage").length != 0 ||
			this.content.getElementsByTagName("OTIntroPage").length != 0 ||
			this.content.getElementsByTagName("OTVideoPage").length != 0 ||
			this.content.getElementsByTagName("OTExamplePage").length != 0 ||
			this.content.getElementsByTagName("OTDisplayPage").length != 0)
			) {
		content = this.content.getElementsByTagName("content")[0].firstChild.nodeValue;
	} else if (this.content != null && 
		    this.content.getElementsByTagName("gapMatchInteraction").length != 0) {
		var assessmentItem = this.content.getElementsByTagName("assessmentItem")[0];
		content = "gapmatch";
	} else {
		content = this.content;
	}
	return content;
}

Node.prototype.isLocked = function() {
	//alert('here');
	var stepIndexInActivity = this.id.substr(this.id.lastIndexOf(":", this.id.length) + 1);
	//alert(stepIndexInActivity);
	if (stepIndexInActivity % 2 == 0) {
		return true;
	}
	return false;
}

function doNothing() {
	//setTimeout("", 5000);
	setTimeout("window.frames['ifrm'].loadXMLString('yay');",500);
	// do nothing
}

/**
 * @Override vle.ContentPanel.prototype.render()
 */
ContentPanel.prototype.render = function(nodeId) {
	var node = this.rootNode.getNodeById(nodeId);
	var content = "";
	if (node.content != null && 
			(node.content.getElementsByTagName("OTReadingPage").length != 0 ||
			node.content.getElementsByTagName("OTIntroPage").length != 0 ||
			node.content.getElementsByTagName("OTVideoPage").length != 0 ||
			node.content.getElementsByTagName("OTExamplePage").length != 0 ||
			node.content.getElementsByTagName("OTDisplayPage").length != 0)
			) {
		content = node.content.getElementsByTagName("content")[0].firstChild.nodeValue;
	} else if (node.content != null && 
		    node.content.getElementsByTagName("gapMatchInteraction").length != 0) {
		//alert('here');
		var assessmentItem = node.content.getElementsByTagName("assessmentItem")[0];
		window.frames["ifrm"].location = "assessment/matchsequence/match.html";   
		//alert(window.frames["ifrm"]);
		window.frames['ifrm'].onload = function(){
			//setTimeout("window.frames['ifrm'].loadXMLString('"+ escape(assessmentItem.textContent) +"');",500);
			//setTimeout("window.frames['ifrm'].loadMElement(assessmentItem);",500);			
			//window.frames['ifrm'].loadMElement(assessmentItem);
		}();

		//alert(assessmentItem);
		//alert(assessmentItem.textContent);
		//alert(assessmentItem.nodeValue);
		//setTimeout("window.frames['ifrm'].loadXMLString('yay');", 5000);
		 
		//window.frames["ifrm"].setTimeout("alert('heyya')",5000);
		return;
	} else  if (node.content != null && 
		    node.content.getElementsByTagName("choiceInteraction").length != 0) {
		window.frames["ifrm"].location = "assessment/multiplechoice/multiplechoice.html";   
		return;
	} else  if (node.content != null && 
		    node.content.getElementsByTagName("OTJournalStep").length != 0) {
		content = "Journal not implemented yet.";
	} else  if (node.content != null && 
		    node.content.getElementsByTagName("OTQuestionAnswer").length != 0) {
		content = "Q&A is written, but needs to be hooked up with portal.";
	} else {
		if (node.content == null) {
			content = node.type;
		} else {
			content = node.content;
		}
	}
	window.frames["ifrm"].document.write(content);   
	window.frames["ifrm"].document.close(); 	
}

/**
 * @Override
 */
function NAVIGATION_LOGIC() {
}

/**
 * @Override
 */
NAVIGATION_LOGIC.prototype.canVisitNode = function(nodeToVisit) {
	for (var i=0; i < vleState.visitedNodes.length; i++) {
		if (vleState.visitedNodes[i].node.id == nodeToVisit.id) {
			//alert("you've already visited this node, so you can't visit it again.");
			return true;
		} else if (nodeToVisit.isLocked()) {
			//alert("This node is locked, so you cannot visit it.");
			return true;
		}
	}
	return true;
}